import java.util.Arrays;
import java.util.Scanner;

public class Main4 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        TeacherManagement teacherManagement = new TeacherManagement(n);
        for (int i = 0; i < n; i++) {
           String string = scanner.nextLine();
           String[] strings = string.split(" ");
           Teacher teacher = new Teacher(Integer.parseInt(strings[0]), strings[1],
                                         Integer.parseInt(strings[2]), strings[3]);
           teacherManagement.add(teacher);
        }
        Arrays.sort(teacherManagement.teachers);
        for (Teacher t:
                teacherManagement.teachers) {
            System.out.println(t);
        }
        teacherManagement.search(scanner.nextLine());
        teacherManagement.search(Integer.parseInt(scanner.nextLine()));
    }
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Teacher[] teachers = new Teacher[2];
        for (int i = 0; i < 2; i++) {
            String string = scanner.nextLine();
            String[] strings = string.split(" ");
            int no = Integer.parseInt(strings[0]);
            String name = strings[1];
            int age = Integer.parseInt(strings[2]);
            String seminary = strings[3];
            teachers[i] = new Teacher(no, name, age, seminary);
            System.out.println(teachers[i]);
        }
        System.out.println(teachers[0].equals(teachers[1]));
    }
}

class Teacher implements Comparable<Teacher> {
    int no;
    String name;
    int age;
    String seminary;

    public Teacher(int no, String name, int age, String seminary) {
        this.no = no;
        this.name = name;
        this.age = age;
        this.seminary = seminary;
    }

    public Teacher() {
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSeminary() {
        return seminary;
    }

    public void setSeminary(String seminary) {
        this.seminary = seminary;
    }

    @Override
    public String toString() {
        return  "no: "  + no +
                ", name:" + name +
                ", age: " + age +
                ", seminary: " + seminary;
    }

//    @Override
//    public int compare(Teacher o1, Teacher o2) {
//        return o2.no - o1.no;
//    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Teacher) {
            Teacher teacher = (Teacher) obj;
            if (teacher.no == this.no)
                return true;
        }
        return false;
    }

    @Override
    public int compareTo(Teacher o) {
        return this.no - o.no;
    }
}

class TeacherManagement {
    Teacher[] teachers;
    int usedSize = 0;

    public TeacherManagement(int n) {
        teachers = new Teacher[n];
    }

    public void add (Teacher teacher) {
        if (usedSize < teachers.length) {
            teachers[usedSize++] = teacher;
        } else {
            throw new ArrayIndexOutOfBoundsException();
        }
    }

    public void search (String name) {
        System.out.println("search by name:");
        int i = 0;
        boolean flg = true;
        while (i < teachers.length) {
            if (teachers[i].name.equals(name)) {
                Teacher teacher = teachers[i];
                System.out.println("no: " + teacher.no + ", name: " +
                        teacher.name + ", age: " + teacher.age +
                        ", seminary: " + teacher.seminary);
                flg = false;
            }
            i++;
        }
        if (flg)
            System.out.println("no such teacher");
    }

    public void search (int age) {
        System.out.println("search by age:");
        int i = 0;
        boolean flg = true;
        while (i < teachers.length) {
            if (teachers[i].age == age) {
                Teacher teacher = teachers[i];
                System.out.println( "no: " + teacher.no + ", name: " +
                        teacher.name + ", age: " + teacher.age +
                        ", seminary: " + teacher.seminary);
                flg = false;
            }
            i++;
        }
        if (flg)
            System.out.println("no such teacher");
    }

}